package com.example.mychatroom.controller;

import com.example.mychatroom.serviceApi.UserService;
import com.example.mychatroom.a_utils.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    public UserService userService;

    @RequestMapping("/subRegister")
    public ResponseBodyMessage<Boolean> registerAcoount(HttpServletRequest request,
                                                        @RequestParam String emailID,
                                                        @RequestParam String emailCode,
                                                        @RequestParam String passwordA,
                                                        @RequestParam String passwordB){
        //构造统一结果的实例
        ResponseBodyMessage<Boolean> responseBodyMessage = new ResponseBodyMessage<>();
        userService.registerAccount(request,emailID,emailCode,passwordA,passwordB,responseBodyMessage);
        return responseBodyMessage;
    }

    @RequestMapping("/sendEmailCode")
    public ResponseBodyMessage<Boolean> sendEmailCode(HttpServletRequest request,@RequestParam String emailId){
        return userService.sendEmailCode(request,emailId);
    }
}
